/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <jpeglib.h>

unsigned char  jpeg[300000];

typedef struct {
  struct jpeg_source_mgr pub;	/* public fields */

  FILE * infile;		/* source stream */
  JOCTET * buffer;		/* start of buffer */
  boolean start_of_file;	/* have we gotten any data yet? */
} my_source_mgr;

typedef my_source_mgr * my_src_ptr;

#define INPUT_BUF_SIZE  1000000	/* choose an efficiently fread'able size */

struct jpeg_decompress_struct cinfo;

void jpeg_read_i(char* filename, int *width, int *height);
void jpeg_read(unsigned char *image,char* filename, int *width, int *height);

int read_jpg(unsigned char *data, char* filename, int *len);
void init_source (j_decompress_ptr cinfo);
int fill_input_buffer (j_decompress_ptr cinfo);
void skip_input_data (j_decompress_ptr cinfo, long num_bytes);
void term_source (j_decompress_ptr cinfo);
void jpeg_mem_src (j_decompress_ptr cinfo, unsigned char *image);
